//
//  WSBaseViewController.m
//  Doctors
//
//  Created by 王森 on 16/4/5.
//  Copyright © 2016年 王森. All rights reserved.
//

#import "WSBaseViewController.h"
#import "CoreStatus.h"
#import "MBProgressHUD+LJ.h"

@interface WSBaseViewController ()<CoreStatusProtocol>

@end

@implementation WSBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //改变导航栏头部标题和颜色
    [self.navigationController.navigationBar setTitleTextAttributes:
     
     @{NSFontAttributeName:[UIFont systemFontOfSize:19],
       
       NSForegroundColorAttributeName:UIColorFromRGB(0x53cac3)}];
    self.view.backgroundColor=UIColorFromRGB(0xf6f6f6);
    
    self.dataArray=[[NSMutableArray alloc]init];

    //监测当前网络
    [CoreStatus beginNotiNetwork:self];
    
    
    if (!CoreStatus.isNetworkEnable) {
        [MBProgressHUD showError:@"当前无网络"];
    }
    

    // Do any additional setup after loading the view.
}
//监测当前网络状态
-(void)coreNetworkChangeNoti:(NSNotification *)noti{
    
    NSString * statusString = [CoreStatus currentNetWorkStatusString];
    
    NSLog(@"当前网络类型：%@\n\n\n\n====\n\n\n\n%@",noti,statusString);
    if ([statusString isEqualToString:@"无网络"]) {
        //提示成功
        MBProgressHUD *newhud = [[MBProgressHUD alloc] initWithView:self.view];
        newhud.userInteractionEnabled = NO;
        [self.view addSubview:newhud];
        newhud.labelText =[NSString stringWithFormat:@"无网络"] ;
        newhud.mode = MBProgressHUDModeText;
        
        [newhud showAnimated:YES whileExecutingBlock:^{
            sleep(1.1);
        } completionBlock:^{
            [newhud removeFromSuperview];
        }];
        
        
    }
    
}

-(void)addLeftBackBtn:(NSString *)btnImg
{
    __weak typeof(self) weakSelf = self;
    NSString *btnName;
    
    if (btnImg==nil) {
        btnName=@"backButton";
    }
    else{
        btnName=btnImg;
    }
    
    [self setLeftImageBarButtonItemWithFrame:CGRectMake(5, 5, 30, 30) image:btnName selectImage:nil action:^(WRBButton *button) {
        
        [weakSelf backBtn:button];
        
    }];
    
    
}
-(void)customTableView
{
    if(!_tableview){
        _tableview = [[UITableView alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT-64) style:UITableViewStylePlain];
        
        _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.backgroundColor= [UIColor colorWithPatternImage:[UIImage imageNamed:@"background_"]];
        [self setExtraCellLineHidden:_tableview];
        
        [self.view addSubview:_tableview];
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableCell"];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TableCell"];
        //        cell.backgroundColor = [UIColor clearColor];
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSLog(@"请重写方法");
}

//隐藏多余线条
-(void)setExtraCellLineHidden: (UITableView *)tableView

{
    
    UIView *view = [UIView new];
    
    view.backgroundColor = [UIColor clearColor];
    
    [tableView setTableFooterView:view];
    
}



/**
 *  页面跳转
 *
 *  @param controller 跳转下一页
 */
-(void)pushNextViewController:(UIViewController *)controller;
{
    
    [self.navigationController pushViewController:controller animated:YES];
    
    
}


-(void)backBtn:(WRBButton *)btn
{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
